package com.project.gcsj5.model;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;

import java.time.Instant;

/**
 * 推荐/书评实体类
 * 用于存储用户对书籍的推荐或评价信息
 */
@TableName // 默认使用类名小写作为表名（recommend）
public class Recommend {

    @TableId(type = IdType.AUTO) // 主键自增策略
    private int id;              // 推荐记录唯一标识ID

    private int user_id;         // 发表推荐的用户ID
    private String title;        // 推荐标题
    private String content;      // 推荐详细内容
    private float star;          // 用户评分（星级）

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "Asia/Shanghai")
    private Instant time;        // 推荐发表时间（带时区格式化）

    private int view_sum;       // 该推荐被查看的次数
    private String img_url;     // 推荐关联的图片URL

    /**
     * 无参构造函数
     */
    public Recommend() {
    }

    /**
     * 全参构造函数
     * @param user_id 用户ID
     * @param id 推荐ID
     * @param title 推荐标题
     * @param star 评分星级
     * @param content 推荐内容
     * @param time 发表时间
     * @param view_sum 浏览次数
     * @param img_url 图片URL
     */
    public Recommend(int user_id, int id, String title, float star, String content, Instant time, int view_sum, String img_url) {
        this.user_id = user_id;
        this.id = id;
        this.title = title;
        this.star = star;
        this.content = content;
        this.time = time;
        this.view_sum = view_sum;
        this.img_url = img_url;
    }

    // 以下是各属性的getter和setter方法

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public int getUser_id() {
        return user_id;
    }

    public void setUser_id(int user_id) {
        this.user_id = user_id;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public Instant getTime() {
        return time;
    }

    public void setTime(Instant time) {
        this.time = time;
    }

    public float getStar() {
        return star;
    }

    public void setStar(float star) {
        this.star = star;
    }

    public int getView_sum() {
        return view_sum;
    }

    public void setView_sum(int view_sum) {
        this.view_sum = view_sum;
    }

    public String getImg_url() {
        return img_url;
    }

    public void setImg_url(String img_url) {
        this.img_url = img_url;
    }

    /**
     * 重写toString方法
     * @return 返回对象的完整字符串表示
     */
    @Override
    public String toString() {
        return "Recommend{" +
                "id=" + id +
                ", user_id=" + user_id +
                ", title='" + title + '\'' +
                ", content='" + content + '\'' +
                ", star=" + star +
                ", time=" + time +
                ", view_sum=" + view_sum +
                ", img_url='" + img_url + '\'' +
                '}';
    }
}